package cn.edu.huanu.dao.impl;

import cn.edu.huanu.dao.BannerDao;
import cn.edu.huanu.exception.DaoException;
import cn.edu.huanu.pojo.Banner;
import cn.edu.huanu.utils.ConnectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hb
 * @date 2025-11-06 15:29:55
 */
public class BannerDaoImpl implements BannerDao {
    @Override
    public List<Banner> queryOnlineBanners() throws DaoException {
        final String sql="select id,imageUrl,title,subtitle,banner_order  from t_banner order by banner_order";

        try {
         return ConnectionUtils.query(sql,r->{
                List<Banner> lists =new ArrayList<>();
                while(r.next()){
                    Banner b=new Banner();
                    b.setId(r.getInt("id"));
                    b.setImageUrl(r.getString("imageUrl"));
                    b.setTitle(r.getString("title"));
                    b.setSubTitle(r.getString("subtitle"));
                    b.setOrder(r.getInt("banner_order"));
                    lists.add(b);
                }
                 return lists;
            });
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
     }
}
